home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / ltick03 / announce.c next >
C/C++ Source or Header  |  1993-07-06  |  3KB  |  180 lines

  1. /*
  2.  *    Announce Engine
  3.  *    (LazyTick project)
  4.  *
  5.  *    Public Domain. May be copied and sold freely.
  6.  */
  7.  
  8. #include    <stdio.h>
  9. #include    <stdlib.h>
  10. #include    <time.h>
  11. #include    <portab.h>
  12. #include    <ctype.h>
  13. #include    <string.h>
  14.  
  15. #include    "tick.h"
  16. #include     "misc.h"
  17. #include    "config.h"
  18. #include     "announce.h"
  19.  
  20. /* global */
  21.  
  22. ANNTICK *firstann=NULL;
  23.  
  24. /* store announce */
  25.  
  26. void announce_tic(BTICFILE *tic, char *group)
  27. {
  28.     ANNTICK *cann;
  29.     char temp[BBSSTR],tempds[ANNDLEN];
  30.     int i,idx,lastspace,lastcut;
  31.  
  32.     /* allocate new entry */    
  33.     if(firstann==NULL)
  34.     {
  35.         cann=firstann=malloc(sizeof(struct _ticlog));
  36.         if(!firstann)
  37.         {
  38.             logline(5,"Malloc error in announce!");
  39.             the_end(242);
  40.         }
  41.         firstann->next=NULL;
  42.     }
  43.     else
  44.     {
  45.         cann=firstann;
  46.         while(cann->next)
  47.             cann=cann->next;
  48.         cann->next=malloc(sizeof(struct _ticlog));
  49.         if(!cann->next)
  50.         {
  51.             logline(5,"Malloc error in announce!");
  52.             the_end(242);
  53.         }
  54.         cann=cann->next;
  55.         cann->next=NULL;
  56.     }
  57.         
  58.     /* do */
  59.     strcpy(cann->group,group);
  60.     strcpy(temp,tic->area);
  61.     strcat(temp,":");
  62.     
  63.     /* description */
  64.     sprintf(tempds,"%-12.12s %4dk %-10.10s %s\n",tic->file,
  65.         (int)tic->size/1024,temp,tic->desc);
  66.     
  67.     if(strlen(tempds)>ANNLLEN)
  68.     {
  69.         idx=ANNSKIP+1;
  70.         lastspace=-1; /* last space, invalid */
  71.         lastcut=0; /* start of current line */
  72.         while(tempds[idx]) /* multiline */
  73.         {
  74.             /* anti overflow */
  75.             if(idx>=strlen(tempds))
  76.                 break;
  77.             
  78.             /* anti inflation, enougn space for one inflation */
  79.             if(strlen(tempds)>(ANNDLEN-ANNSKIP-2))
  80.             {    
  81.                 tempds[idx]=0;
  82.                 break;
  83.             }
  84.             
  85.             /* lastspace */
  86.             if(tempds[idx]==' ')
  87.                 lastspace=idx;
  88.                 
  89.             if((idx-lastcut)>ANNLLEN)
  90.             {
  91.                 /* if no spaces in current string cut here */
  92.                 if((lastspace>idx) || (lastspace<lastcut))
  93.                     lastspace=idx;
  94.                 
  95.                 /* cut at <lastspace> */    
  96.                 tempds[lastspace]='\n';
  97.                 lastcut=lastspace+1;
  98.                 lastspace=-1; /* reset lastspace */
  99.                 
  100.                 /* inflate with spaces beginning of new line */
  101.                 for(i=0;i<ANNSKIP;i++)
  102.                 {    
  103.                     idx++;
  104.                     strspins(tempds+lastcut+i);
  105.                 }
  106.             }
  107.             idx++;
  108.         }
  109.     }
  110.     /* done */
  111.     strcpy(cann->display,tempds);
  112. }
  113.  
  114. int process_announce(char *group, char *arearad, char *footer)
  115. {
  116.     ANNTICK *cura;
  117.     char tempfile[BBSSTR];
  118.     char buffer[BBSSTR];
  119.     char subject[BBSSTR];
  120.     FILE *tf;
  121.     FILE *foot;
  122.     int something=0;
  123.     
  124.     strcpy(tempfile,get_ticktemp());
  125.     strcat(tempfile,"TICKANN.TMP");
  126.     
  127.     tf=fopen(tempfile,"w");
  128.     if(!tf)
  129.         logline(4,"Can't open %s",tempfile);
  130.     else
  131.     {
  132.         fprintf(tf,"\n");
  133.         
  134.         cura=firstann;
  135.         while(cura)
  136.         {
  137.             if(!stricmp(cura->group,group))
  138.             {
  139.                 fprintf(tf,cura->display);
  140.                 something++;
  141.             }
  142.             cura=cura->next;
  143.         }
  144.         
  145.         if(footer)
  146.         {
  147.             if(footer[0])
  148.             {
  149.                 foot=fopen(footer,"r");
  150.                 if(foot)
  151.                 {
  152.                     while(fgets(buffer,BBSSTR-2,foot)!=NULL)
  153.                         fputs(buffer,tf);
  154.                     fclose(foot);
  155.                 }
  156.                 else
  157.                     logline(3,"Can't open footer %s",footer);
  158.             }
  159.         }
  160.         else
  161.             fprintf(tf,"\nFile request or download from this node.\n");
  162.             
  163.         fclose(tf);
  164.         
  165.         if(something)
  166.         {
  167.             sprintf(subject,"New file(s) received in %s.",group);
  168.             logline(0,"Writing message to %s",arearad);
  169.             postmsg(LAZYNAME,NULL,"All",NULL,subject,
  170.                     arearad,tempfile,0);
  171.         }
  172.     }
  173.     
  174.     if(remove(tempfile))
  175.         logline(3,"Can't remove announce temp. file");
  176.     
  177.     if(something)
  178.         return BBSOK;
  179.     return BBSFAIL; /* nothing announced */
  180. }